import re

def validator(column_name, column, rules, custom_tips=dict()):
    for rule in rules:
        if rule == 'require':
            if column is None:
                return False, '%s cannot be None.' % column_name
            elif len(column) < 1:
                require_tips = custom_tips.get('require')
                if require_tips:
                    return False, '%s.' % require_tips
                return False, '%s cannot be empty.' % column_name
        elif rule == 'number':
            regex = re.compile(r'^\d+$')
            if regex.match(column) is None:
                number_tips = custom_tips.get('number')
                if number_tips:
                    return False, '%s.' % number_tips
                return False, '%s can only be numbers' % column_name
        elif re.compile(r'^max:\d+$').match(rule):
            max_length = int(rule[rule.index(':')+1:])
            if len(column) > max_length:
                max_tips = custom_tips.get('max:%d' % max_length)
                if max_tips:
                    return False, '%s.' % max_tips
                return False, '%s more than %d characters' % (column_name, max_length)
        elif re.compile(r'^min:\d+$').match(rule):
            min_length = int(rule[rule.index(':')+1:])
            if len(column) < min_length:
                min_tips = custom_tips.get('min:%d' % min_length)
                if min_tips:
                    return False, '%s.' % min_tips
                return False, '%s must not be less than %d characters' % (column_name, min_length)
    return True, 'Verification success'

def validate(*args):
    results = []
    for item in args:
        for child_item in item:
            column_name = child_item[0]
            column = child_item[1]
            rules = child_item[2]
            rules = rules.split('|')
            if len(child_item) >= 4:
                custom_tips = child_item[3]
                res = validator(column_name, column, rules, custom_tips)
                results.append({'result': res[0], 'message': res[1]})
            res = validator(column_name, column, rules)
            results.append({'result': res[0], 'message': res[1]})

    for result in results:
        if not result.get('result'):
            return result.get('result'), result.get('message')
    return results[0].get('result'), results[0].get('message')





